#!/usr/bin python3
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    s = input()
    n = int(input())

    count_t = 0
    for i in s:
        if i == 'T':
            count_t += 1

    if count_t >= n:
        print(len(s) - count_t + n)
    else:
        tmp = n - count_t
        if tmp % 2 == 0:
            print(len(s))
        else:
            print(len(s) - 1)